#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,l,V;
struct node{
    int d,v,a;
};
node car[100005];
ll de[100005];
//vector<int> tect[100005];
ll bucket[100005];
void solve(){
    memset(car,0,sizeof(car));
    memset(de,0,sizeof(de));
    cin>>n>>m>>l>>V;
    for(int i=1;i<=n;i++){
        cin>>car[i].d>>car[i].v>>car[i].a;
    }
    for(int i=1;i<=n;i++){
        cin>>de[i];
    }
    ll sum=0;
    for(int i=1;i<=n;i++){
        bool flag=0;
        double xingshi=(V*V-car[i].v*car[i].v)*1.0/(2*car[i].a);
        double now=xingshi+car[i].d;
        if(car[i].v<=V && car[i].a>0){
            for(int j=1;j<=m;j++){
                if(de[j]>now){
                    flag=1;
                }
            }
        }else if(car[i].v>V){
            if(car[i].a>=0){
                for(int j=1;j<=m;j++){
                    if(de[j]>=car[i].d){
                        flag=1;
                    }
                }
            }else{
                for(int j=1;j<=m;j++){
                    if(de[j]>=car[i].d&&de[j]<now){
                        flag=1;
                    }
                }
            }
        }
        if(flag) sum++;
    }
    cout<<sum<<endl;
    int ans=0;

    //sort(bucket+1,bucket+m+1);
    //for(int i=1;i<=m;i++){
       // if()
    //}
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
